package com.jade.journal.appender;

import com.jade.framework.base.util.DataUtils;
import com.jade.journal.AbstractAppender;
import com.jade.journal.JournalEvent;
import com.jade.journal.JournalFormat;
import com.jade.journal.desc.AppenderDesc;
import com.jade.journal.desc.JournalDesc;

/**
 * 流式追加器。
 *
 * @author sky
 * @version 1.0 14-9-22 下午1:05
 */
public abstract class StreamAppender extends AbstractAppender
{
    protected JournalFormat format;
    protected String encoding = "UTF-8";

    public StreamAppender(String type, JournalDesc desc, AppenderDesc appenderDesc)
    {
        super(type, desc, appenderDesc);
    }

    /**
     * 设置格式化器
     *
     * @param format 格式化
     */
    public void setFormat(JournalFormat format)
    {
        this.format = format;
    }

    /**
     * 返回格式化器
     *
     * @return JournalFormat 格式化器
     */
    public JournalFormat getFormat()
    {
        return format;
    }

    /**
     * 设置字符集
     *
     * @param encoding 字符集
     */
    public void setEncoding(String encoding)
    {
        this.encoding = encoding;
    }

    /** 返回字符集 */
    public String getEncoding()
    {
        return encoding;
    }

    @Override
    public void init(JournalEvent event)
    {
        super.init(event);
        encoding = DataUtils.getString(appenderDesc.getProperty("encoding"), encoding);
    }
}
